package com.pingan.haofang.searchcloud.batch.common;

import java.util.HashMap;
import java.util.Map;

/**
 * 历史操作记录处理器工厂
 * 
 * @author LUYI374
 * @date 2017年2月17日
 * @since 1.0.0
 */
public class BatchRunnerFactory {

    private static final Map<String, BatchRunInstance> RUNNER_MAP = new HashMap<String, BatchRunInstance>();

    /**
     * 注册batch runner，须确保handlerName全局唯一
     * 
     * @param runnerName
     * @param beanName
     * @param bean
     * @param method
     */
    public synchronized static void addRunner(String runnerName, BatchRunInstance instance) {
        if (RUNNER_MAP.containsKey(runnerName)) {
            throw new ExceptionInInitializerError(
                    "duplicate batchHandler detected, [" + runnerName + "], please check");
        } else {
            RUNNER_MAP.put(runnerName, instance);
        }
    }

    public static BatchRunInstance getRunner(String runnerName) {
        return RUNNER_MAP.get(runnerName);
    }

}
